package dynamicrange;

import ikelib.menuUtil;
import ikelib.wintime;

import javax.swing.DefaultListModel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ListModel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.MenuBar;

import javax.swing.JList;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.PrinterJob;

import java.util.Iterator;

import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.JButton;

import javax.swing.JLabel;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.JComboBox;

import wcg.ChannelDataCollection;
import wcg.stateChangeNotify;
import wcg.winDataBase;
import wcg.winDataBaseChange;
import wcg.winchkgPanelInterface;
import javax.swing.border.CompoundBorder;
import javax.swing.border.BevelBorder;

public class DynamicRangePanel extends JPanel implements stateChangeNotify ,ActionListener,MenuListener ,winchkgPanelInterface{

	private static final long serialVersionUID = 1L;
	private JPanel jPanelWest = null;		  
	private JList jListChannel = null;		
	private DynamicRangeView jPanelSNRView = null;	//@
	private JScrollPane jScrollPane = null;
	private JButton jButtonAutoScale = null;
	private JButton jButtonYZoomIn = null;
	private JButton jButtonYZoomOut = null;
	private JButton jButtonShiftUp = null;
	private JButton jButtonShiftDown = null;
	private JButton jButtonTimeZoomIn = null;
	private JButton jButtonTimeZoomOut = null;
	private JButton jButtonShiftRight = null;
	private JButton jButtonShiftLeft = null;
	private JButton jButtonManual = null;
	
	private DynamicRangeAmpDialog SNRAmpDlg = null; //@
	private winDataBase	Data = null;  //@
	private JButton jButtonSnapShot = null;
	
	private double AmpMax = 0.0;
	private double AmpMin = 0.0;
	private JLabel jLabelLogo = null;
	private JLabel jLabelAmplitudeGroupe1 = null;
	private JLabel jLabelAmplitudeGroupe11 = null;
	private JComboBox jComboBoxFilter = null;
	private JLabel jLabelAmplitudeGroupe111 = null;
	
	/**
	 * This is the default constructor
	 */
	public DynamicRangePanel() {
		super();
		initialize();
		this.add(getJPanelSNRView(), BorderLayout.CENTER); //@
		add(getPanelSouth(), BorderLayout.SOUTH);
		SNRAmpDlg = new DynamicRangeAmpDialog(null); //@
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(400, 550);
		this.setLayout(new BorderLayout());
		this.add(getJPanelWest(), BorderLayout.WEST);
	}

	/**
	 * This method initializes jPanelWest	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelWest() {
		if (jPanelWest == null) {
			jLabelLogo = new JLabel();
			jLabelLogo.setBounds(new Rectangle(2, 3, 125, 21));
			jLabelLogo.setText("");
			jLabelLogo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/datamark_bar_21.png")));
			jPanelWest = new JPanel();
			jPanelWest.setPreferredSize(new Dimension(180,500));
			jPanelWest.setLayout(null);
			jPanelWest.add(jLabelLogo, null);
			jPanelWest.add(getPanelAmp());
			jPanelWest.add(getPanelTime());
			jPanelWest.add(getPanelFilter());
			jPanelWest.add(getPanelChannels());
		}
		return jPanelWest;
	}

	/**
	 * This method initializes jListChannel	
	 * 	
	 * @return javax.swing.JList	
	 */
	private boolean firstView=true;
	private JButton jButtonShiftLeft2 = null;
	private JButton jButtonShiftRight2 = null;
	private JLabel jLabelStartTime = null;
	private JLabel jLabelSpan = null;
	private JButton jButtonFitTime = null;
	private JButton jButtonAutoAmplitude = null;
	private JPanel panelAmp;
	private JPanel panelTime;
	private JPanel panelFilter;
	private JPanel panelSouth;
	private JPanel panelChannels;
	private JList getJListChannel() {
		if (jListChannel == null) {
			jListChannel = new JList();
			jListChannel.setLocation(0, 25);
			jListChannel.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
				public void valueChanged(javax.swing.event.ListSelectionEvent e) {
					ListModel model = jListChannel.getModel(); //@
					int max = model.getSize();
					for(int i=0;i<max;i++){
						boolean disp = jListChannel.isSelectedIndex(i);
						String ms = (String)jListChannel.getModel().getElementAt(i);
						int ch = Integer.valueOf(ms,16);	
						getJPanelSNRView().showChannel(ch,disp);//@
					}
					if(firstView){
						getJPanelSNRView().autoScale();
						firstView=false;
					}
					getJPanelSNRView().repaintAll();//@
				}
			});
		}
		return jListChannel;
	}

	/**
	 * This method initializes jPanelSNRView	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	public DynamicRangeView getJPanelSNRView() {
		if (jPanelSNRView == null) {
			jPanelSNRView = new DynamicRangeView(this); //@jve:decl-index=0
		}
		return jPanelSNRView;
	}
	public void setwinDataBase(winDataBase d){
		Data=d;
		getJPanelSNRView().setDataBase(d);
	//	jPanelSpectrumView.setWinDataBase(d);
	}
	public void doGetChannel(){
		getJListChannel().removeAll();
		DefaultListModel model = new DefaultListModel(); //@
		//Iterator<Integer> ite = Data.getChannel().iterator();
		Iterator<Integer> ite = Data.iteratorChannel();
		while(ite.hasNext()){
			int ch = ite.next();
			String channel = new String();
			channel=String.format("%01X%01X%01X%01X", (ch>>12)&0xf,(ch>>8)&0xf,(ch>>4)&0xf,(ch>>0)&0xf);
			model.addElement(channel);
		}
		getJListChannel().setModel(model);
	}
	
	//------------------------------------------------------------------------
	private int GetSelectedChannel(){
		ListModel model= getJListChannel().getModel(); //@
		int index=getJListChannel().getSelectedIndex();
		if(index<0) return -1;
		String chtxt = (String)model.getElementAt(index);
		
		int ret = 0;
		try{
			ret = Integer.parseInt(chtxt,16);
		} catch(NumberFormatException e){
			e.printStackTrace();
		}
		return ret;
	}
	//------------------------------------------------------------------------
	// 元のデータベースが変化したとき呼び出される
	private void OnChangeData(){
		// ------------------------------
		// ｃｈをえらんで
	//	int ch = GetSelectedChannel();
		getJPanelSNRView().setTimeLatest();
		getJPanelSNRView().setData();
		
	}
	//------------------------------------------------------------------------
	// 元のデータベースが変化したとき呼び出される
	public void OnChangeDataBase(int hint,int ch,ChannelDataCollection dcol){
		switch(hint){
		case winDataBaseChange.EVENT_CHANNEL_CLEAR:
		case winDataBaseChange.EVENT_CHANNEL_ADD:
		case winDataBaseChange.EVENT_CHANNEL_REMOVE:
			doGetChannel();
			break;
		case winDataBaseChange.EVENT_DATA_CLEAR:
			break;
		case winDataBaseChange.EVENT_DATA_REMOVE:
			break;
		case winDataBaseChange.EVENT_DATA_PUT:
			//OnChangeData();
			break;
		}
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(6, 27, 70, 87);
			jScrollPane.setViewportView(getJListChannel());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jButtonAutoScale	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAutoScale() {
		if (jButtonAutoScale == null) {
			jButtonAutoScale = new JButton();
			jButtonAutoScale.setBounds(79, 84, 95, 25);
			jButtonAutoScale.setText("AutoScale");
			jButtonAutoScale.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getJPanelSNRView().autoScale();
				}
			});
		}
		return jButtonAutoScale;
	}

	/**
	 * This method initializes jButtonYZoomIn	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonYZoomIn() {
		if (jButtonYZoomIn == null) {
			jButtonYZoomIn = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/plus.gif")));
			jButtonYZoomIn.setBounds(41, 23, 24, 25);
			jButtonYZoomIn.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					double max = getJPanelSNRView().getYDispMax();
					double min = getJPanelSNRView().getYDispMin();
					double span = max-min;
					span = span/2;
					max -= span/2;
					min += span/2;
					getJPanelSNRView().setYDispMax(max);
					getJPanelSNRView().setYDispMin(min);
					getJPanelSNRView().repaintAll();
				}
			});
		}
		return jButtonYZoomIn;
	}

	/**
	 * This method initializes jButtonYZoomOut	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonYZoomOut() {
		if (jButtonYZoomOut == null) {
			jButtonYZoomOut = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/minus.gif")));
			jButtonYZoomOut.setBounds(41, 49, 24, 24);

			jButtonYZoomOut.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					double max = getJPanelSNRView().getYDispMax();
					double min = getJPanelSNRView().getYDispMin();
					double span = max-min;
					span = span*2;
					max += span/2;
					min -= span/2;
					getJPanelSNRView().setYDispMax(max);
					getJPanelSNRView().setYDispMin(min);
					getJPanelSNRView().repaintAll();
				}
			});
		}
		return jButtonYZoomOut;
	}

	/**
	 * This method initializes jButtonShiftUp	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonShiftUp() {
		if (jButtonShiftUp == null) {
			jButtonShiftUp = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/arrow_up.png")));
			jButtonShiftUp.setBounds(12, 24, 24, 24);
			//jButtonShiftUp.setText("");
			jButtonShiftUp.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					double max = getJPanelSNRView().getYDispMax();
					double min = getJPanelSNRView().getYDispMin();
					double span = max-min;
					span = span*0.2;
					max += span/2;
					min += span/2;
					getJPanelSNRView().setYDispMax(max);
					getJPanelSNRView().setYDispMin(min);
					getJPanelSNRView().repaintAll();
				}
			});
		}
		return jButtonShiftUp;
	}

	/**
	 * This method initializes jButtonShiftDown	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonShiftDown() {
		if (jButtonShiftDown == null) {
			jButtonShiftDown = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/arrow_down.png")));
			jButtonShiftDown.setBounds(12, 49, 24, 24);
			jButtonShiftDown.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					double max = getJPanelSNRView().getYDispMax();
					double min = getJPanelSNRView().getYDispMin();
					double span = max-min;
					span = span*0.2;
					max -= span/2;
					min -= span/2;
					getJPanelSNRView().setYDispMax(max);
					getJPanelSNRView().setYDispMin(min);
					getJPanelSNRView().repaintAll();
				}
			});
		}
		return jButtonShiftDown;
	}

	/**
	 * This method initializes jButtonTimeZoomIn	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonTimeZoomIn() {
		if (jButtonTimeZoomIn == null) {
			jButtonTimeZoomIn = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/wave-zoomin.png")));
			jButtonTimeZoomIn.setBounds(149, 108, 24, 24);
			jButtonTimeZoomIn.setToolTipText("Zoom in time (x2). SHIFT+click for fine adjust(x1.33).");
			jButtonTimeZoomIn.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int ratio;
					int ratio2;
					if((e.getModifiers() & ActionEvent.SHIFT_MASK)==0){ ratio = 1; ratio2 = 2;}
					else 											 {	ratio = 3; ratio2 = 4;}
					timeZoom(ratio,ratio2);
				}
			});
		}
		return jButtonTimeZoomIn;
	}

	/**
	 * This method initializes jButtonTimeZoomOut	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonTimeZoomOut() {
		if (jButtonTimeZoomOut == null) {
			jButtonTimeZoomOut = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/wave-zoomout.png")));
			jButtonTimeZoomOut.setBounds(111, 108, 24, 24);
			jButtonTimeZoomOut.setToolTipText("Zoom out time (x0.5). SHIFT+click for fine adjust(0.75).");
			jButtonTimeZoomOut.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int ratio;
					int ratio2;
					if((e.getModifiers() & ActionEvent.SHIFT_MASK)==0){ ratio = 2; ratio2 = 1;}
					else 											 {	ratio = 4; ratio2 = 3;}
					timeZoom(ratio,ratio2);
				}
			});
		}
		return jButtonTimeZoomOut;
	}
	/*
	 * 
	 */
	private void timeZoom(int ratio,int ratio2){
		getJPanelSNRView().setTimeScaleZoom(ratio,ratio2,0.5f);
		getJPanelSNRView().repaintAll();
	}
	/**
	 * This method initializes jButtonShiftRight	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonShiftRight() {
		if (jButtonShiftRight == null) {
			jButtonShiftRight = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/arrow_right.png")));
			jButtonShiftRight.setBounds(110, 76, 24, 24);
			jButtonShiftRight.setToolTipText("Shift time forward (1/8). SHIFT+click for fine adjust(1/16).");
			jButtonShiftRight.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int ratio;
					if((e.getModifiers() & ActionEvent.SHIFT_MASK)==0)	ratio = 8;
					else												ratio = 16;
					spanShift(true,ratio);
				}
			});
		}
		return jButtonShiftRight;
	}

	/**
	 * This method initializes jButtonShiftLeft	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonShiftLeft() {
		if (jButtonShiftLeft == null) {
			jButtonShiftLeft = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/arrow_left.png")));
			jButtonShiftLeft.setBounds(43, 76, 24, 24);;
			jButtonShiftLeft.setToolTipText("Shift time backward(1/8). SHIFT+click for fine adjust(1/16).");
			jButtonShiftLeft.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int ratio;
					if((e.getModifiers() & ActionEvent.SHIFT_MASK)==0) 	ratio = 8;
					else 												ratio = 16;
					spanShift(false,ratio);
				}
			});
		}
		return jButtonShiftLeft;
	}
	/*
	 * 時間シフト
	 */
	private void spanShift(boolean inc,int ratio){
	
		getJPanelSNRView().setTimeScaleShift( inc,ratio);
		getJPanelSNRView().repaintAll();
	}
	/**
	 * This method initializes jButtonManual	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonManual() {
		if (jButtonManual == null) {
			jButtonManual = new JButton();
			jButtonManual.setBounds(86, 49, 88, 24);
			jButtonManual.setText("manual");
			jButtonManual.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					double max,min;
					if(AmpMax == 0.0 && AmpMin==0.0){
						max = getJPanelSNRView().getYDispMax();
						min = getJPanelSNRView().getYDispMin();
					}
					else{
						max = AmpMax; min = AmpMin;
					}
					SNRAmpDlg.Span   = max - min;
					SNRAmpDlg.Center = (max + min)/2;
					SNRAmpDlg.updateData(true);
					SNRAmpDlg.setDialogLocationCenter(  jPanelSNRView);
					SNRAmpDlg.setVisible(true);
					if(SNRAmpDlg.OK){
						double span = SNRAmpDlg.Span;
						double center = SNRAmpDlg.Center;
						max = center + span/2;
						min = center - span/2;
						getJPanelSNRView().setYDispMax(max);
						getJPanelSNRView().setYDispMin(min);
						AmpMax=max; AmpMin=min;
						getJPanelSNRView().repaintAll();
					}
				}
			});
		}
		return jButtonManual;
	}

	/**
	 * This method initializes jButtonSnapShot	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSnapShot() {
		if (jButtonSnapShot == null) {
			jButtonSnapShot = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/camera.png")));;
			jButtonSnapShot.setPreferredSize(new Dimension(24,24));
			jButtonSnapShot.setToolTipText("Take snapshot to .png file");
			jButtonSnapShot.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String dir = getJPanelSNRView().ExportImageDir;
					if(dir == null) dir = Data.getWriteOutFolder();
					getJPanelSNRView().exportAsImage(dir,1.0,1.0);
				}
			});
		}
		return jButtonSnapShot;
	}

	/**
	 * This method initializes jComboBoxFilter	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxFilter() {
		if (jComboBoxFilter == null) {
			jComboBoxFilter = new JComboBox();
			jComboBoxFilter.setBounds(10, 30, 137, 22);
			// メニューを作成
			String[] mes = getJPanelSNRView().getFilterModeString();
			for(int i=0;i<mes.length;i++){
				jComboBoxFilter.addItem(mes[i]);
			}
			int cidx = jPanelSNRView.getFilterModeIndex();
			jComboBoxFilter.setSelectedIndex(cidx);
			jComboBoxFilter.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					//　フィルタを選択
					int idx = jComboBoxFilter.getSelectedIndex();
					jPanelSNRView.setFilterModeIndex(idx);
				}
			});
		}
		return jComboBoxFilter;
	}

	/**
	 * This method initializes jButtonShiftLeft2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonShiftLeft2() {
		if (jButtonShiftLeft2 == null) {
			jButtonShiftLeft2 = new JButton(new ImageIcon(getClass()
					.getClassLoader().getResource("images/arrow2_left.png")));
			jButtonShiftLeft2.setBounds(11, 76, 24, 24);
			jButtonShiftLeft2.setToolTipText("Shift time backward(1/2). SHIFT+click for fine adjust.1/4)");
			jButtonShiftLeft2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int ratio;
					if((e.getModifiers() & ActionEvent.SHIFT_MASK)==0)	ratio = 2;
					else												ratio = 4;
					spanShift(false,ratio);
				}
			});
		}
		return jButtonShiftLeft2;
	}

	/**
	 * This method initializes jButtonShiftRight2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonShiftRight2() {
		if (jButtonShiftRight2 == null) {
			jButtonShiftRight2 = new JButton(new ImageIcon(getClass()
					.getClassLoader().getResource("images/arrow2_right.png")));
			jButtonShiftRight2.setBounds(149, 76, 24, 24);
			jButtonShiftRight2.setToolTipText("Shift time forward(1/2). SHIFT+click for fine adjust(1/4).");
			jButtonShiftRight2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int ratio;
					if((e.getModifiers() & ActionEvent.SHIFT_MASK)==0)	ratio = 2;
					else												ratio = 4;
					spanShift(true,ratio);
				}
			});
		}
		return jButtonShiftRight2;
	}
	private void onChangeTime(){
		wintime start = getJPanelSNRView().getDispStartTime();
		int     span  = getJPanelSNRView().getDispTimeMin();
		jLabelStartTime.setText(start.fmt());
		jLabelSpan.setText(String.format("%d min",span));

	}

	/**
	 * This method initializes jButtonFitTime	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonFitTime() {
		if (jButtonFitTime == null) {
			jButtonFitTime = new JButton();
			jButtonFitTime.setBounds(92, 15, 81, 28);
			jButtonFitTime.setText("Auto");  // Generated
			jButtonFitTime.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					getJPanelSNRView().autoScaleTime();
				}
			});
		}
		return jButtonFitTime;
	}

	/**
	 * This method initializes jButtonAutoAmplitude	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonAutoAmplitude() {
		if (jButtonAutoAmplitude == null) {
			jButtonAutoAmplitude = new JButton();
			jButtonAutoAmplitude.setBounds(86, 24, 88, 24);
			jButtonAutoAmplitude.setText("Auto");  // Generated
			jButtonAutoAmplitude.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					getJPanelSNRView().autoScaleAmplitude();
				}
			});
		}
		return jButtonAutoAmplitude;
	}

	@Override
	public void onStateChange(int hint) {
		onChangeTime();
		onFilterChange();
	}
	private void onFilterChange(){
		int index;
		index = jPanelSNRView.getFilterModeIndex();
		jComboBoxFilter.setSelectedIndex(index);
	}
	

	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
	}

	/* (non-Javadoc)
	 * @see javax.swing.event.MenuListener#menuCanceled(javax.swing.event.MenuEvent)
	 */
	@Override
	public void menuCanceled(MenuEvent arg0) {
		
	}

	/* (non-Javadoc)
	 * @see javax.swing.event.MenuListener#menuDeselected(javax.swing.event.MenuEvent)
	 */
	@Override
	public void menuDeselected(MenuEvent arg0) {
		
	}

	/* (non-Javadoc)
	 * @see javax.swing.event.MenuListener#menuSelected(javax.swing.event.MenuEvent)
	 */
	@Override
	public void menuSelected(MenuEvent arg0) {
		
	}

	/* (non-Javadoc)
	 * @see wcg.winchkgPanelInterface#addMenu(java.awt.MenuBar)
	 */
	@Override
	public void addMenu(JMenuBar mb) {
		
		JMenu menuFile = menuUtil.getMenu(mb,"File");
		if(menuFile == null){
			menuFile = menuUtil.setupMenu("File",KeyEvent.VK_F,"File",this);
			mb.add(menuFile);
		}

		JMenuItem menuPrint = menuUtil.setupMenuItem("Print",KeyEvent.VK_P,"PrintSNR",this);
		menuPrint.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/printer.png")));
		
		menuPrint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//--------------------------------------------------------
				// SNRViewの印刷
				PrinterJob job = PrinterJob.getPrinterJob();
				job.setPrintable(jPanelSNRView);
				job.setJobName("winchkg-SNR");
				PageFormat page = new PageFormat();
				page.setOrientation(PageFormat.LANDSCAPE);
				Paper pp = new Paper();
				pp.setSize(210*72/25.4, 297*72/25.4);
				pp.setImageableArea(0.25*72, 0.25*72, 210*72/25.4 - 0.5*72,  297*72/25.4-0.5*72);

				page.setPaper(pp);
				job.pageDialog(page);
				if(job.printDialog()){
					try{
						job.print();
					}
					catch(Exception e){

					}
				}

			}

		});
		menuFile.add(menuPrint);
		
	}

	
	
	private JPanel getPanelAmp() {
		if (panelAmp == null) {
			panelAmp = new JPanel();
			panelAmp.setBorder(new TitledBorder(null, "Amplitude", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panelAmp.setBounds(0, 153, 180, 87);
			panelAmp.setLayout(null);
			panelAmp.add(getJButtonShiftUp());
			panelAmp.add(getJButtonYZoomIn());
			panelAmp.add(getJButtonShiftDown());
			panelAmp.add(getJButtonYZoomOut());
			panelAmp.add(getJButtonAutoAmplitude());
			panelAmp.add(getJButtonManual());
		}
		return panelAmp;
	}
	private JPanel getPanelTime() {
		if (panelTime == null) {
			panelTime = new JPanel();
			panelTime.setBorder(new TitledBorder(null, "Time", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panelTime.setBounds(1, 241, 180, 150);
			panelTime.setLayout(null);
			panelTime.add(getJButtonFitTime());
			jLabelStartTime = new JLabel();
			jLabelStartTime.setBounds(11, 47, 162, 24);
			panelTime.add(jLabelStartTime);
			jLabelStartTime.setText("Start time");  // Generated
			jLabelStartTime.setBorder(new LineBorder(Color.lightGray,1,true));
			panelTime.add(getJButtonShiftLeft2());
			panelTime.add(getJButtonShiftLeft());
			panelTime.add(getJButtonShiftRight());
			panelTime.add(getJButtonShiftRight2());
			jLabelSpan = new JLabel();
			jLabelSpan.setBounds(11, 108, 86, 24);
			panelTime.add(jLabelSpan);
			jLabelSpan.setText("Span");  // Generated
			jLabelSpan.setBorder(new LineBorder(Color.lightGray,1,true));
			panelTime.add(getJButtonTimeZoomOut());
			panelTime.add(getJButtonTimeZoomIn());
			jLabelSpan.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					getJPanelSNRView().doTimeSpanDialog();
				}
			});
			
						jLabelStartTime.addMouseListener(new java.awt.event.MouseAdapter() {
							public void mouseClicked(java.awt.event.MouseEvent e) {
								getJPanelSNRView().doTimeSetDialog();
							}
						});
		}
		return panelTime;
	}
	private JPanel getPanelFilter() {
		if (panelFilter == null) {
			panelFilter = new JPanel();
			panelFilter.setBorder(new TitledBorder(null, "Filter", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panelFilter.setBounds(2, 396, 180, 67);
			panelFilter.setLayout(null);
			panelFilter.add(getJComboBoxFilter());
		}
		return panelFilter;
	}
	private JPanel getPanelSouth() {
		if (panelSouth == null) {
			panelSouth = new JPanel();
			panelSouth.setLayout(new BorderLayout(0, 0));
			panelSouth.add(getJButtonSnapShot(), BorderLayout.EAST);
		}
		return panelSouth;
	}
	private JPanel getPanelChannels() {
		if (panelChannels == null) {
			panelChannels = new JPanel();
			panelChannels.setBorder(new TitledBorder(null, "Channels", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panelChannels.setBounds(0, 21, 180, 131);
			panelChannels.setLayout(null);
			panelChannels.add(getJScrollPane());
			panelChannels.add(getJButtonAutoScale());
		}
		return panelChannels;
	}
}  
//  @jve:decl-index=0:visual-constraint="8,10"
